<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>v-bind动态绑定class</title>
    <style>
      .active {
        color: red;
      }
      .fs30 {
        font-size: 30px;
      }
      .fwb {
        font-weight: bold;
      }

      li {
        margin-bottom: 10px;
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <!-- 1、绑定数组 -->
      <h2 :class="['active', 'fs30']">我是h2标签</h2>
      <p :class="['active', isBold ? 'fwb' : '']">我是p标签</p>

      <!-- 2、绑定对象 -->
      <h3 :class="{ active: isActive }">我是h3标签</h3>
      <button @click="isActive = !isActive">变色</button>

      <!-- 3、作业练习 -->
      <ul>
        <li
          v-for="(item, index) in movies"
          :key="index"
          @click="selectItem(index)"
          :class="{ active: currentIndex === index }"
        >
          {{ item }}
        </li>
      </ul>
    </div>

    <script src="./lib/vue_v2.6.14.js"></script>
    <script>
      const app = new Vue({
        el: '#app',
        data: {
          isBold: true,
          isActive: false,
          movies: ['速度与激情', '泰坦尼克号', '战狼', '银河补习班'],
          currentIndex: ''
        },
        methods: {
          selectItem(index) {
            this.currentIndex = index;
          }
        }
      });
    </script>
  </body>
</html>
